
package uk.org.cardboardbox.nfcpointstracker.dialog;

import uk.org.cardboardbox.nfcpointstracker.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class PinDialog extends AlertDialog {

    public interface Listener {
        public void onPinEntered(String pin);

        public void onCancelled();
    }

    private final Listener listener;

    private TextView pin;

    public PinDialog(Context context, Listener listener) {
        super(context);
        this.listener = listener;
        init(context);
    }

    private final void init(Context context) {
        setTitle("Pin");
        LayoutInflater li = (LayoutInflater)context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View content = li.inflate(R.layout.pin, null);
        pin = (TextView)content.findViewById(R.id.pin_pin);
        setView(content);
        setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel),
                new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        listener.onCancelled();
                    }
                });
        setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                listener.onPinEntered(pin.getEditableText().toString());
            }
        });
    }
}
